package tk.deep.bh2.event;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import tk.deep.bh2.dao.mapper.OrderDetailMapper;

import javax.annotation.Resource;


/**
 * Application event to be handle.
 *
 * @author Asin Liu
 * @version 1.0.0
 * @since 1.0.0
 */
@Slf4j
@Component
public class ApplicationEventInit {

    @Resource
    OrderDetailMapper mapper;

    @EventListener(ApplicationStartedEvent.class)
    public void run() {
        log.info(">>> ApplicationStartedEvent fired!");
        try {
          mapper.insertOrderDetails();
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        log.info(">>> ApplicationStartedEvent ended. ");
    }
}
